﻿@model Webdiyer.WebControls.Mvc.IPagedList<HouseAgencySite.Models.Areas>
@using HouseAgencySite.Utils;
@{
    ViewBag.Title = "地区列表";
    Layout = "~/Areas/Admin/Views/Shared/_ListLayout.cshtml";
}


@{
    List<SelectListItem> list = HouseAgencySite.Utils.ParamHelper.Areas(0, "", Request["City"], true);
    List<SelectListItem> listArea = null;
    List<SelectListItem> listAddress = null;
    if (list.Count > 1)
    {
        listArea = HouseAgencySite.Utils.ParamHelper.Areas(1, list[1].Text, Request["Area"], true);
    }
    if (listArea.Count > 1)
    {
        listAddress = HouseAgencySite.Utils.ParamHelper.Areas(2, listArea[1].Text, Request["AddressName"], true);
    }
}
@section query{
    <table class="table table-bordered">
        <tr>
            <td>市</td>
            <td>
                @Html.DropDownList("City", list, new { @class = "form-control", style = "width:150px" })
            </td>
            <td>区</td>
            <td>
                @if (listArea.Count > 0)
                { 
                    @Html.DropDownList("Area", listArea, new { @class = "form-control", style = "width:150px" })
                }
            </td>
            <td>地址</td>
            <td>
                @if (listAddress.Count > 0)
                { 
                    @Html.DropDownList("AddressName", listAddress, new { @class = "form-control", style = "width:150px" })
                }
            </td>
            <td>
                <input type="submit" value="查询" id="btnSearch" class="btn btn-primary" /></td>
        </tr>

    </table>
}
@section toolbar{
  @*  @Html.ActionLink("新增", "Create", null, new { @class = "btn btn-primary" })*@

    <a href="javascript:void(0);" onclick="Edit('@Url.Action("Create", "Areas", null)',500,600,null)" class="btn btn-primary">新增</a> 
}
@section list{
    <table class="table table-bordered">

        <tr class="btn-success">
            <th>序号</th>
            <th>市
            </th>
            <th>区
            </th>
            <th>地名      
            </th>
            <th>创建时间
            </th>
            <th>创建人
            </th>
            <th>修改时间
            </th>
            <th>修改人
            </th>

            <th>操作</th>
        </tr>
        @{
            int i = 0;
        }
        @foreach (var item in Model)
        {
            <tr class="@(i % 2 == 0 ? "success" : "warning")">
               <td>@(i + 1+(Model.CurrentPageIndex-1)*10)</td>
                <td>
                    @Html.DisplayFor(modelItem => item.City)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Area)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.AddressName)
                </td>


                <td>
                    @Html.DisplayFor(modelItem => item.CreateTime)
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.CreateUserName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ModifyTime)
                </td>

                <td>
                    @Html.DisplayFor(modelItem => item.ModifyUserName)
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="Edit('@Url.Action("Edit", "Areas", new { id = item.Guid })',500,600,null)" class="btn btn-primary btn-xs">编辑</a> |
                    <a href="javascript:void(0);" onclick="openModalPage('@Url.Action("Details", "Areas", new { id = item.Guid })',0,600,null)" class="btn btn-primary btn-xs">查看</a>|
                    <a href="javascript:void(0);" onclick="Delete('@Url.Action("Delete", "Areas", new { id = item.Guid })')" class="btn btn-primary btn-xs">删除</a>
                </td>
            </tr>
            i++;
        }

    </table>
}
<div class="text-center">@Html.HtmlPager(Model)</div>
<script>
    $(function () {
        ///绑定地区select函数
        var BindCountryRegion = function (sel, type, area) {
            $.ajax({
                url: "@Url.Action("GetAreaNames")", async: false, data: { areaType: type, areaName: area }, success: function (d) {
                    $("select[id=" + sel + "]").html("");
                    if (d.length > 0) {
                        $("select[id=" + sel + "]").append("<option value=''>全部</option>");
                        for (var i = 0; i < d.length; i++) {
                            $("select[id=" + sel + "]").append("<option>" + d[i].Text + "</option>");
                        }
                    }

                }
            });
        }

    
        //市选择事件
        $("select[id=City]").change(function (event, provincevalue) {
            if ($(this).val() != "") {
                BindCountryRegion("Area", 1, $(this).val());
                $("Area").removeAttr("disabled");
                $("input[id=FullPath]").val($(this).val());
            }
            if (typeof (provincevalue) != "undefined") {
                $("#City").val(provincevalue);
            }
            changeItem($(this), "City");
        });
        //地区择事件
        $("select[id=Area]").change(function (event, cityvalue) {
            if ($(this).val() != "") {
                BindCountryRegion("AddressName", 2, $(this).val());
            }
            if (typeof (cityvalue) != "undefined") {
                $("#Area").val(cityvalue);
            }

        });
    })
</script>
